package com.qdu.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet("/loginout")
public class LoginOut extends HttpServlet {

    public LoginOut() {
        super();
    }

    public void destroy() {
        super.destroy(); 
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        HttpSession session = request.getSession();
        String method = request.getParameter("method").trim();
        session.invalidate();
        if (method.equals("user")) {
            request.getRequestDispatcher("login.jsp").forward(request, response);
        }
        else if (method.equals("admin")) {
            request.getRequestDispatcher("admin/login.jsp").forward(request, response);
        }
        else if (method.equals("center")) {
            request.getRequestDispatcher("index.jsp").forward(request, response);
        }
    }
    public void init() throws ServletException {
     
    }

}
